package juc;

/**
 * @author fangkun
 * @create 2022-12-09-13:48
 */

import java.util.concurrent.TimeUnit;

/**
 * 三个售票员卖完50张票，总量完成即可，售票员每个月固定月薪
 */
public class ThreadLocalDemo {
    public static void main(String[] args) {
        MovieTicket movieTicket = new MovieTicket();

        for (int i = 1; i <= 3; i++) {
            new Thread(() -> {
                for (int j = 0; j < 20; j++) {
                    movieTicket.saleTicket();
                    try { TimeUnit.MILLISECONDS.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); }
                }
            },String.valueOf(i)).start();
        }
    }
}

class MovieTicket{
    int number = 50;

    public synchronized void saleTicket(){
        if (number > 0){
            System.out.println(Thread.currentThread().getName()+"\t"+"号售票员卖出第： "+(number--));
        }else{
            System.out.println("--------------卖完了");
        }
    }
}